package com.spring.validator_test;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class FormController {
	//https://blog.csdn.net/qwe6112071/article/details/51049743
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		//核心组件：PropertyEditorRegistrySupport
		binder.registerCustomEditor(Employee.class, new EmployeeEditor());
	}
	@RequestMapping("/emp")
	public String emp(Employee employee){
		System.out.println(employee);

		employee.setAge(111);

		return "validate";
	}

	@RequestMapping("/formtest")
	public String formtest(Employee employee){
		System.out.println(employee);

		employee.setAge(33333);

		return "validate";
	}
	@RequestMapping("/custom_convert")
	public String customConvert(@RequestParam("employee") Employee employee){
		System.out.println(employee);

		return "validate";
	}


}
